<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<title>${SYSTEM_NAME}</title>
	<meta name="renderer" content="webkit">
	<meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
	<meta name="viewport" content="width=device-width, initial-scale=1.0, minimum-scale=1.0, maximum-scale=1.0, user-scalable=0">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/layui/css/layui.css?v=${FILE_VERSION}" media="all">
	<link rel="stylesheet" href="${pageContext.request.contextPath}/static/layuiadmin/style/admin.css?v=${FILE_VERSION}" media="all">
</head>
<body>
	<div class="layui-fluid">
       	<div class="layui-card">
         	<div class="layui-card-header">代码生成器表管理</div>
         	<div class="layui-card-body">
         		<div class="layui-form layer-query">
					<div class="layui-form-item">
						<div class="layui-inline">
							<label class="layui-form-label">表名：</label>
							<div class="layui-input-inline">
								<input type="text" placeholder="请输入表名" id="tableName" class="layui-input">
							</div>
						</div>
						<div class="layui-inline">
							<button class="layui-btn layui-btn-primary layui-border-blue" onclick="reload()">查询</button>
						</div>
					</div>
				</div>
         		<hr class="layui-bg-green">
           		<table class="layui-table" lay-filter="tableList" id="layerTable">
				</table>
         	</div>
       	</div>
  	</div>

	<script type="text/html" id="toolbar">
		<div class="layui-btn-container">
			<button class="layui-btn layui-btn-primary layui-border-blue" onclick="createAllTable()">导入数据库表</button>
		</div>
	</script>
  	
	<script type="text/html" id="barTpl">
  		<a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="edit">编辑</a>
  		<a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="del">删除</a>

		<a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="fieldManage">列管理</a>
		<a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs " lay-event="reloadTable">重新生成表</a>
		<a class="layui-btn layui-btn-primary layui-border-blue layui-btn-xs" lay-event="generatorCreate">代码生成</a>

		<a class="layui-btn layui-btn-primary layui-border-red layui-btn-xs" lay-event="generatorDelete">代码删除</a>

	</script>

	<script src="${pageContext.request.contextPath}/static/js/common-2.0.0.js?v=${FILE_VERSION}"></script>
  	<script src="${pageContext.request.contextPath}/static/layuiadmin/layui/layui.js?v=${FILE_VERSION}"></script>
  	<script src="${pageContext.request.contextPath}/static/js/jquery-3.3.1.min.js?v=${FILE_VERSION}"></script>
	<script src="${pageContext.request.contextPath}/static/js/common/core-2.0.0.js?v=${FILE_VERSION}"></script>
  	<script>
  		var table;
	  	layui.use(['table', 'element'], function() {
			var element = layui.element;
			table = layui.table;
			table.render({ 
				elem : '#layerTable',
				even : "true",
				height: 'full-260',
				toolbar: '#toolbar',
				defaultToolbar: ['filter', 'exports', 'print'],
				limit: 10,
				limits: [10,30,50,100],
				id : 'tableList',
				url : getContextPath() + '/generator/table/list/listInfo',
				page : true,
				method : 'post',
				cols : [[
					{field : 'tableName',minWidth : 140,title : "数据库表名"}
					,{field : 'className',width : 140,title : "类名称"}
					,{field : 'tableComment',width : 140,title : "类注释"}
					,{field : 'moudleName',width : 140,title : "模块名称"}
					,{field : 'fileDirName',width : 140,title : "文件夹名"}
					,{field : 'shiro',width : 140,title : "权限"}
					,{field : 'modelInherits',width : 140,title : "model继承类"}
					,{field : 'pageModelName',width : 120,title : "页面模板"}
					,{field : 'menuParentId',width : 120,title : "父级菜单"}
					,{field : 'isAlreadyName',width : 120,title : "是否生成过"}
					,{filed: 'needFileName',width : 160,title : "需要生成的文件"}
					,{fixed: 'right', width:460, align:'center',title:"操作", toolbar: '#barTpl'}
				]],
				request : {
					pageName : 'current', //页码的参数名称，默认：page
					limitName : 'size' //每页数据量的参数名，默认：limit
				}
			//如果无需自定义请求参数，可不加该参数
			});

			//监听工具条
			table.on('tool(tableList)', function(obj) {
				var data = obj.data;
				if (obj.event === 'del') {
					deleteById(data,obj,'/generator/table/del/deleteById');
				} else if (obj.event === 'edit') {
					addLayer('/generator/table/edit/input', data.id);
				}else if (obj.event === 'reloadTable') {
					reloadTable(data.id);
				}else if (obj.event === 'generatorCreate') {
					generatorCreate(data.id);
				}else if (obj.event === 'fieldManage') {
					filedManage(data.id,data.tableComment);
				}else if (obj.event === 'generatorDelete') {
					generatorDelete(data.id);
				}
			});
		});

		function reload() {
			table.reload('tableList', {
				where : {
					"tableName" : $("#tableName").val()
				}
			});
		}

		function createAllTable(){
			layer.confirm('您确定要导入新的数据库表吗？', function(index){
				$ajax({
					url: "/generator/table/createAllTable",
					succCallback: function (json) {
						if(json.code == 0)
							reload();
					}
				});
			});
		}

		function reloadTable(id){
			layer.confirm('您确定要重新创建此数据库表吗？', function(index){
				$ajax({
					url: "/generator/table/reloadTable",
					data: {
						"id" : id
					},
					succCallback: function (json) {
						if(json.code == 0)
							reload();
					}
				});
			});
		}

		function generatorCreate(id){
			layer.confirm('您确定要生成此数据表的代码吗？将覆盖已有代码。', function(index){
				$ajax({
					url: "/generator/table/generatorCreate",
					data: {
						"id" : id
					},
					succCallback: function (json) {
						if(json.code == 0)
							reload();
					}
				});
			});
		}

		function generatorDelete(id){
			layer.confirm('您确定要删除此数据表的代码吗？此操作不能恢复，请谨慎操作!。', function(index){
				$ajax({
					url: "/generator/table/generatorDelete",
					data: {
						"id" : id
					},
					succCallback: function (json) {
						if(json.code == 0)
							reload();
					}
				});
			});
		}

		function filedManage(id,classComment){
			var url = getContextPath() + "/generator/field/list?tableId=" + id;
			layer.open({
				title : classComment + "列管理",
				type: 2,
				area: ['95%', '95%'],
				anim: 2,
				content: [url, 'yes']
			});
		}

  	</script>
</body>
</html>
